// Decompiled by:       Fernflower v0.6
// Date:                28.11.2010 03:55:55
// Copyright:           2008-2009, Stiver
// Home page:           http://www.reversed-java.com

import I.I;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import net.minecraft.client.MinecraftApplet;

public class MCUtils {

   private static Cipher KKLI(int var0, String var1) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, InvalidAlgorithmParameterException {
      Random var2 = new Random(43287234L);
      byte[] var3 = new byte[8];
      var2.nextBytes(var3);
      PBEParameterSpec var4 = new PBEParameterSpec(var3, 5);
      SecretKey var5 = null;
        try {
            var5 = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(var1.toCharArray()));
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(MCUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
      Cipher var6 = null;
        try {
            var6 = Cipher.getInstance("PBEWithMD5AndDES");
        } catch (NoSuchPaddingException ex) {
            Logger.getLogger(MCUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
      var6.init(var0, var5, var4);
      return var6;
   }

   private static boolean Z(AtomicReference var0, AtomicReference var1) {
      try {
         File var2 = new File(I.I(), "lastlogin");
         Cipher var3 = KKLI(2, "passwordfile");
         DataInputStream var4;
         if(var3 != null) {
            var4 = new DataInputStream(new CipherInputStream(new FileInputStream(var2), var3));
         } else {
            var4 = new DataInputStream(new FileInputStream(var2));
         }

         var0.set(var4.readUTF());
         var1.set(var4.readUTF());
         var4.close();
         return true;
      } catch (Exception var5) {
         var5.printStackTrace();
         return false;
      }
   }

   private static boolean add(AtomicReference var0, AtomicReference var1) {
      JPanel var2 = new JPanel();
      var2.setLayout(new GridLayout(4, 1));
      JTextField var3 = new JTextField(12);
      JPasswordField var4 = new JPasswordField(12);
      var2.add(new JLabel("Username"));
      var2.add(var3);
      var2.add(new JLabel("Password"));
      var2.add(var4);
      JFrame var5 = new JFrame("Minecraft Login");
      var5.setDefaultCloseOperation(3);
      var5.setSize(300, 300);
      var5.setLocationRelativeTo((Component)null);
      var5.setVisible(false);
      int var6 = JOptionPane.showConfirmDialog(var5, var2, "Put username and password", 2, 3);
      if(var6 == 0) {
         var0.set(var3.getText());
         var1.set(new String(var4.getPassword()));
         return true;
      } else {
         return false;
      }
   }

   private static gi addWindowListener(String var0, String var1) {
      String[] var2 = append(var0, var1);
      if(var2.length < 3) {
         return null;
      } else {
         Frame var3 = new Frame("Minecraft");
         Canvas var4 = new Canvas();
         var3.setLayout(new BorderLayout());
         var3.add(var4, "Center");
         var4.setPreferredSize(new Dimension(854, 480));
         var3.pack();
         var3.setLocationRelativeTo((Component)null);
         gi var5 = new gi(var3, var4, (MinecraftApplet)null, 854, 480, false, var3);
         Thread var6 = new Thread(var5, "Minecraft main thread");
         var6.setPriority(10);
         var5.l = false;
         var5.j = "www.minecraft.net";
         var5.i = new dz(var2[2].trim(), var2[3].trim());
         var3.setVisible(true);
         var3.addWindowListener(new gm(var5, var6));
         var6.start();
         return var5;
      }
   }

   public static final gi I() {
      AtomicReference var0 = new AtomicReference();
      AtomicReference var1 = new AtomicReference();
      gi var2 = null;
      if(Z(var0, var1)) {
         var2 = addWindowListener((String)var0.get(), (String)var1.get());
         if(var2 != null) {
            return var2;
         }
      }

      while(add(var0, var1)) {
         var2 = addWindowListener((String)var0.get(), (String)var1.get());
         if(var2 != null) {
            break;
         }

         JOptionPane.showMessageDialog((Component)null, "Incorrect username or password.", "MCCheat", 0);
      }

      return var2;
   }

   public static final String[] append(String var0, String var1) {
      String var2 = "";

      try {
         var2 = "user=" + URLEncoder.encode(var0, "UTF-8") + "&password=" + URLEncoder.encode(var1, "UTF-8") + "&version=" + 12;
      } catch (UnsupportedEncodingException var5) {
         var5.printStackTrace();
      }

      String var3 = close("http://www.minecraft.net/game/getversion.jsp", var2);
      if(var3 == null) {
         return new String[0];
      } else if(!var3.contains(":")) {
         return new String[0];
      } else {
         String[] var4 = var3.split(":");
         return var4;
      }
   }

   public static final String close(String var0, String var1) {
      HttpURLConnection var2 = null;

      DataOutputStream var4;
      try {
         URL var3 = new URL(var0);
         var2 = (HttpURLConnection)var3.openConnection();
         var2.setReadTimeout(3000);
         var2.setConnectTimeout(3000);
         var2.setRequestMethod("POST");
         var2.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
         var2.setRequestProperty("Content-Length", Integer.toString(var1.getBytes().length));
         var2.setRequestProperty("Content-Language", "en-US");
         var2.setUseCaches(false);
         var2.setDoInput(true);
         var2.setDoOutput(true);
         var4 = new DataOutputStream(var2.getOutputStream());
         var4.writeBytes(var1);
         var4.flush();
         var4.close();
         InputStream var5 = var2.getInputStream();
         BufferedReader var6 = new BufferedReader(new InputStreamReader(var5));
         StringBuffer var7 = new StringBuffer();

         String var8;
         while((var8 = var6.readLine()) != null) {
            var7.append(var8);
            var7.append('\r');
         }

         var6.close();
         String var9 = var7.toString();
         return var9;
      } catch (SocketTimeoutException var15) {
         JOptionPane.showMessageDialog((Component)null, "Failure to connect to Minecraft.net, please try again later.", "MCCheat", 2);
         System.exit(0);
         var4 = null;
      } catch (UnknownHostException var16) {
         JOptionPane.showMessageDialog((Component)null, "Failure to connect to Minecraft.net, please try again later.", "MCCheat", 2);
         System.exit(0);
         var4 = null;
         return "0";
      } catch (Exception var17) {
         var17.printStackTrace();
         var4 = null;
         return "0";
      } finally {
         if(var2 != null) {
            var2.disconnect();
         }

      }

      return "0";
   }
}
